package com.alticor.amwaychina.contentHub;

import android.content.Context;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class FileCopy {

    public static void copyFile(final Context context , final String fileName){

        final File file = new File(context.getExternalFilesDir(null).getPath()+"/"+fileName);
        if(!file.exists()){
            //复制文件
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try{
                        InputStream inputStream = context.getAssets().open(fileName);
                        OutputStream outputStream = new FileOutputStream(file);
                        byte[] buffer = new byte[1444];
                        int readSize = 0;
                        while ((readSize = inputStream.read(buffer)) != 0){
                            outputStream.write(buffer,0,readSize);
                        }
                        inputStream.close();
                        outputStream.close();
                    }catch (Exception e){
                        e.toString();
                    }

                }
            });
            thread.start();
        }
    }
}
